<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
	
	
	
	 //登陆页面
	public function index()
	{
		$data=array();
		$data['error_msg']=$this->uri->segment(4);
     	$this->load->view("admin/login",$data);
     
	}
	
	//处理后台登陆
	public function do_adminlogin()
	{
		$name = $this->input->post('agentname');
		$password = $this->input->post('agentpassword');
		
		$this->_check_yzm1();

		$this->load->model('Agent_model');
		$_agenter = $this->Agent_model->check_agentlogin($name,$password);
		//print_r($_agenter);
		if ($_agenter){
			
			$bSupperadmin=($_agenter['userid']==1 || $_agenter['AgencyCode']=="airadmin");
			$agenter = array(
				   'uadmin_name'  => $_agenter['Name'],
				   'uadmin_userid'  => $_agenter['userid'],
				   'uadmin_account'  => $_agenter['AgencyCode'],
				   'uadmin_in' => TRUE,
				   'uadmin_last_login' => $_agenter['lastlogindate'],
				   'uadmin_access' 	=> $_agenter['menuaccess'],
				   'uadmin_maincurrency' => $_agenter['MainCurrency'],
				   'uadmin_SYSGROUP' => $_agenter['SYSGROUP'],
				   'uadmin_Supper'	   => $bSupperadmin,
				   'uadmin_hashcode' => $_agenter['AuthorizedKey']
			   );
			$this->session->set_userdata($agenter);
            
			$this->Agent_model->update_last_login($_agenter['userid']);
			
			//echo "登陆成功";
			redirect('admin/home/mainface');

			
		}else{
			//echo "login fail";
			if($this->input->post("from")!="")
			{
				redirect($this->input->post("from").'/index/Password_Error');
			}else
			{
				redirect('admin/home/index/Password_Error');
			}
			
		}
		
	}
	//操作界面
	public function mainface()
	{
		if(!$this->session->userdata("uadmin_in"))
		{
			redirect("admin/home");
			exit();
		}
		$data=array();
		$data['adminname']		=$this->session->userdata("uadmin_name");
		$data['menuaccess']		=",".$this->session->userdata("uadmin_access");
		$data['lastlogintime']	=$this->session->userdata("uadmin_last_login");
		$data['uadmin_Supper']	=(boolean)$this->session->userdata("uadmin_Supper");
		$data['SYSGROUP']		=$this->session->userdata("uadmin_SYSGROUP");
		
		$this->load->model("Setting_model");
		$data["armenu"]=$this->Setting_model->get_menu($data['SYSGROUP']);

		
		$this->load->view("admin/index",$data);
	}
	
	//登出
	public function logout()
	{
		if($this->session->userdata("uadmin_account")=="flyguam")
		{
			
			$this->session->sess_destroy();
			redirect('flyguam/admin');
		
		}else
		{
		
			$this->session->sess_destroy();
			redirect('admin');	
		}
		
	}
	//校验登陆码
	function _check_yzm1()
	{
		session_start();
        	$Verifier = $this->input->post('CheckCode');
        	if (!empty($_SESSION['verify1']) && $_SESSION['verify1'] == $Verifier)
        	{

	   	}else
	   	{
	   		if($this->input->post("from")!="")
			{
				redirect($this->input->post("from").'/index/verifier1');
			}else
			{
				redirect('admin/home/index/verifier1');
			}
			
	   	}
		return;
	}
	
	public function noaccess()
	{
		echo "No Access";	
	}
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */